<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.android.c2dm.server.PMF" %>
<%@ page import="javax.jdo.Query" %>
<%@ page import="com.example.jumpnote.android.server.DeviceInfo" %>

<html>
  <body>

<%
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
%>
<p>Hello, <%= user.getNickname() %>! (You can
<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>.)</p>
<%
    } else {
%>
<p>Hello!
<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">Sign in</a>
to include your name with greetings you post.</p>
<%
    }
%>
<table>
<tr>
<td></td><td width="60">key</td><td width="300">RegisteredID</td>
</tr>
<%
    PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + DeviceInfo.class.getName();
    List<DeviceInfo> devices = (List<DeviceInfo>) pm.newQuery(query).execute();
    if (!devices.isEmpty())  {
        for (DeviceInfo d : devices) {
%>
<tr>
<td><input type="checkbox" /></td><td width="60"><%=d.getKey()%></td><td width="300"><%=d.getDeviceRegistrationID()%></td>
</tr>
<%
        }
    }
    pm.close();
%>
</table>
<form action="/sign" method="post">
    <div align="center">key:<input type="text" name="email" ></input></div>
    <div align="center">DeviceId:<input type="text" name="deviceId" ></input></div>
    <div align="center">RegistrationId:<textarea type="text" name="registrationId" ></textarea></div>
    <div align="center"><input type="submit" value="reginster" /></div>
  </form>
  </body>
</html>